/*
 * adlibr - Library for mobile AD mediation.
 * http://adlibr.com
 * Copyright (c) 2012 Mocoplex, Inc.  All rights reserved.
 * Licensed under the BSD open source license.
 */

/*
 * confirmed compatible with cauly SDK 1.4.7
 */

package com.crom.android.lottebaseball.ad;

import com.cauly.android.ad.AdListener;
import com.mocoplex.adlib.AdlibConfig;
import com.mocoplex.adlib.SubAdlibAdViewCore;

import android.content.Context;
import android.util.AttributeSet;

// ������몃� �댁���CAULY SDK 媛�� 臾몄�瑜�李몄“�댁＜�몄�.
public class SubAdlibAdViewCauly extends SubAdlibAdViewCore  {
	
	protected com.cauly.android.ad.AdView ad;

	public SubAdlibAdViewCauly(Context context) {
		this(context,null);
	}	
	
	public SubAdlibAdViewCauly(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		// �ш린��CAULY ID瑜�����⑸���
		String caulyID = "eDIjqpdr";
		
		com.cauly.android.ad.AdInfo ai = new com.cauly.android.ad.AdInfo();
		ai.initData(caulyID, "cpc",
				AdlibConfig.getInstance().getCaulyGender(),
				AdlibConfig.getInstance().getCaulyAge(),
				AdlibConfig.getInstance().getCaulyGPS(),
				"default",
				"yes",30,true);

		ad = new com.cauly.android.ad.AdView(this.getContext());				
	}
		
	// �ㅼ�以�����������쇰� �몄��⑸���
	// �ㅼ�濡�愿��瑜�蹂댁�二쇨린 �������껌�⑸���		
	public void query()
	{
		ad.setAdListener(new AdListener(){

			@Override
			public void onCloseInterstitialAd() {
				
			}

			@Override
			public void onFailedToReceiveAd(boolean arg0) {

				failed();
			}

			@Override
			public void onReceiveAd() {
				
				// 愿����� �깃났				
				// ���愿����寃쎌�留�蹂댁�寃�CAULY SDK 臾몄� 李몄“
				if(ad.isChargeableAd())
				{
					// 愿��瑜��������쇰㈃ �대� �������㈃������⑸���
					gotAd();					
				}
				else
				{
					failed();
				}				
			}
			
		});
		
		this.addView(ad);
		
		// ��㈃��癒쇱� 蹂댁� 愿��媛����吏�����⑸���
		gotAd();
	}
	
	public void clearAdView()
	{
		if(ad != null)
		{
			ad.stopLoading();
			ad.destroy();
			ad = null;			
		}
		
		super.clearAdView();
	}
	
	public void onResume()
	{
		ad.startLoading();
		super.onResume();
	}
	public void onPause()
	{
		ad.stopLoading();
		super.onPause();
	}	
}
